﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ModuleCustomerEdit.ViewModel;
using ServerConnection.ShopServiceReference;

namespace ModuleCustomerEdit.View
{
    /// <summary>
    /// Interaction logic for CustomerEdit.xaml
    /// </summary>
    public partial class CustomerEdit : UserControl, ICustomerEdit
    {
        public CustomerEdit()
        {
            InitializeComponent();
        }

        public ViewModel.ICustomerEditViewModel ViewModel
        {
            get;
            set;
        }

        public void Load (User data)
        {
            ViewModel = new CustomerEditViewModel();
            ViewModel.Load(data);
            DataContext = ViewModel;
        }

        private void btn_ok_Click(object sender, RoutedEventArgs e)
        {
            CustomerEditViewModel model = ((CustomerEditViewModel)DataContext);

            if (model.OkClickCommand.CanExecute(model.User))
            {
                try
                {
                    model.OkClickCommand.Execute(model.User);
                    MessageBox.Show("All is ok!");
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message);
                }
            }
            else
            {
                MessageBox.Show("Not all fields is correct!");
            }
        }
    }
}